package com.heima.controller;


import com.heima.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class HelloController {

    // 快速入门的案例
    @GetMapping("/basic")
    public String test(Model model) {


        //1.纯文本形式的参数
        model.addAttribute("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        model.addAttribute("stu", student);

        return "01-basic";
    }



    // 测试list集合案例
    @GetMapping("/list")
    public String list(Model model) {
        List<Student> students = new ArrayList<>();

        Student student1 = new Student();
        student1.setName("张三");
        student1.setAge(18);
        student1.setMoney(0F);
        students.add(student1);

        Student student2 = new Student();
        student2.setName("李四");
        student2.setAge(18);
        student2.setMoney(1F);
        students.add(student2);

        model.addAttribute("stu", students);
        return "02-basic";
    }

    // 测试map集合案例
    @GetMapping("/map")
    public String map(Model model) {

        Student student1 = new Student();
        student1.setName("张三");
        student1.setAge(18);
        student1.setMoney(0F);

        Student student2 = new Student();
        student2.setName("李四");
        student2.setAge(18);
        student2.setMoney(1F);

        Map<String, Object> map = new HashMap<>();
        map.put("stu1", student1);
        map.put("stu2", student2);

        model.addAttribute("map",map);
        return "02-basic";
    }


}
